package com.example.doudou.demos.controller;
import com.example.common.domain.R;
import com.example.doudou.demos.aspect.AuditLog;
import com.example.doudou.demos.aspect.SystemLog;
import com.example.doudou.demos.pojo.enums.ErrorEnum;
import com.example.doudou.demos.pojo.enums.OperateEnum;
import com.example.doudou.demos.utils.BusinessException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p> @Title DemoController
 * <p> @Description 待统计接口
 *
 * @author ACGkaka
 * @date 2021/3/31 17:24
 */
@RestController
@Slf4j
@Api(tags = "Demo控制层")
public class DemoController {

    @GetMapping("/index")
    @SystemLog(module = "首页", method = "hello", operateType = "SELECT", logType = "1")
    @ApiOperation(value = "首页")
    public String index() {
        return "<h1>Hello World.</h1>";
    }

    @GetMapping("login")
    @ApiOperation(value = "登录")
    @SystemLog(module = "首页", method = "login", operateType = "LOGIN", logType = "1")
    public String login() {
        int i = 1 / (Math.random() > 0.5 ? 0 : 1);
        return "测试报错的AOP方法";
    }

    @GetMapping(value = "test", produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "测试日志记录")
    @AuditLog(action = "测试日志记录", type = OperateEnum.SELECT,isRecordParam = false)
    public R test(@RequestParam(value = "op", required = false)String op) {
        if ("99".equals(op)){
            throw new BusinessException(ErrorEnum.A0428);
        }
        return R.ok("测试数据");
    }
}
